


from openpyxl.reader.excel import load_workbook
import openpyxl
import sys
from xlrd import open_workbook # xlrd用于读取xld
import xlwt
# 用于写入xls
workbook = open_workbook(r'./寄存器、网关json、iotjson标示符使用表.xls')  # 打开xls文件
# 读取excel2007文件
# wb = load_workbook(filename=r'./寄存器、网关json、iotjson标示符使用表.xls')
sheet_name= workbook.sheet_names()  # 打印所有sheet名称，是个列表
sheet = workbook.sheet_by_index(0)  # 根据sheet索引读取sheet中的所有内容
sheet1= workbook.sheet_by_name('Sheet1')  # 根据sheet名称读取sheet中的所有内容
print(sheet.name, sheet.nrows, sheet.ncols)  # sheet的名称、行数、列数
for r in range(sheet.nrows):
    for c in range(sheet.ncols):
        print(sheet.cell(r,c).value)
# content = sheet.col_values(0)  # 第六列内容
# print(content)
# 取第一张表
# sheetnames = wb.sheetnames
# wb2 = openpyxl.Workbook()
# for sheet in sheetnames:
#     ws = wb[sheet]
    # ws2 = wb2.create_sheet(title=sheet)
    # ws2.cell(row=1, column=1, value="二维码内容")
    # ws2.cell(row=1, column=2, value="#")
    # ws2.cell(row=1, column=3, value="番号")
    # r = 1
    # # for rx in range(3, ws.max_row + 1):
    # for rx in range(1, ws.max_row + 1):
    #     w1 = str(ws.cell(row=rx, column=1).value).strip().replace("待调试", "0").replace("SP件", "0")
    #     w2 = str(ws.cell(row=rx, column=2).value).strip().replace("待调试", "0").replace("SP件", "0")
    #     w3 = str(ws.cell(row=rx, column=3).value).strip().replace("待调试", "0").replace("SP件", "0")
    #     w4 = str(ws.cell(row=rx, column=4).value).strip().replace("待调试", "0").replace("SP件", "0")
    #
    #     # if not w2 == "None" and not w3 == "None" and not w4 == "None":
    #     if not w2 == "None" and not w3 == "None":
    #         print(w1, w2, w3)
    #         if w1.isspace() or w2.isspace() or w3.isspace() or w4.isspace():
    #             pass
    #         else:
                # r += 1
                # w2w3w4 = w2 + ' ' + w3 + " " + w4
                # c1 = ''.join([strQ2B(v) for v in w2w3w4])
                # c1 = ''.join([strQ2B(v) for v in w1])
                # c2 = ''.join([strQ2B(v) for v in w2])
                # c3 = ''.join([strQ2B(v) for v in w3])
                # print(c1, c2, c3)

                # ws2.cell(row=r, column=1, value=c1)
                # ws2.cell(row=r, column=2, value=c2)
                # ws2.cell(row=r, column=3, value=c3)

# ws0 = wb2["Sheet"]
# ws1 = wb2["Sheet1"]
# ws2 = wb2["Sheet2"]
# ws3 = wb2["SP件出货明细"]
# ws4 = wb2["Sheet4"]
# wb2.remove(ws0)
# wb2.remove(ws1)
# wb2.remove(ws2)
# wb2.remove(ws3)
# wb2.remove(ws4)
# wb2.save('控制箱信息-数据已筛选处理.xlsx')  # 保存数据
# wb2.close()
